frappe.listview_settings["Logistics Billing Detail Inst"] = {
  onload(listview) {
    listview.page.add_action_item(__("Approve Fee"), function () {
      const selected = listview.get_checked_items() || [];
      if (!selected.length) {
        frappe.msgprint(__("Please select at least one row to approve."));
        return;
      }
      const names = selected.map((d) => d.name).filter(Boolean);
      if (!names.length) {
        frappe.msgprint(__("No valid rows selected."));
        return;
      }

      frappe.prompt(
        {
          fieldname: "reason",
          label: __("Charge Reason"),
          fieldtype: "Small Text",
          reqd: 1,
        },
        (values) => {
          frappe.call({
            method: "upsystem.upsystem.api_logistics_charging.approve_logistics_billing_details",
            freeze: true,
            freeze_message: __("Approving selected fees and applying charges..."),
            args: {
              detail_names: JSON.stringify(names),
              charge_reason: values.reason || "",
            },
            callback: function (r) {
              if (!r.exc) {
                frappe.msgprint(
                  (r.message && r.message.message) ||
                    __("Selected fee details approved successfully.")
                );
                listview.refresh();
              }
            },
          });
        },
        __("Approve Selected Fees"),
        __("Confirm")
      );
    });
  },
};


